﻿using DocumentFormat.OpenXml.Office2010.ExcelAc;
using MediatR;
using SmartProduction.Domain;
using SmartProduction.ErrorCode;
using SmartProduction.Infarstructrue.Interface;
using SmartProduction.Read.API.Application.Commands.BomCommand;

namespace SmartProduction.Read.API.Application.CommandHandlers.BomCommandHandler
{
    public class BomPartsQueryCommandHandler : IRequestHandler<BomPartsQueryCommand, APIResult<List<BomParts>>>
    {
        /// <summary>
        /// 工艺流程仓储
        /// </summary>
        private readonly IBaseRepository<BomParts> partsRepository;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mapper">映射</param>
        /// <param name="procRepository">bom配件仓储</param>
        public BomPartsQueryCommandHandler(IBaseRepository<BomParts> partsRepository)
        {
            this.partsRepository = partsRepository;
        }
        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request">命令</param>
        /// <param name="cancellationToken">重置</param>
        /// <returns></returns>
        public Task<APIResult<List<BomParts>>> Handle(BomPartsQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<BomParts>> result = new APIResult<List<BomParts>>();
            var entity = partsRepository.GetAll().Result;
            if (request.BomId != 0)
            {
                entity = entity.Where(x => x.BomId == request.BomId);
            }
            result.Code = APIEnums.查询成功;
            result.Msg = APIEnums.查询成功.ToString();
            result.data = entity.ToList();
            return  Task.FromResult(result);
        }

       
       
    }
}
